﻿// =============================================================================
// XPathDebugger And Examples SimpleSplitter.cs
// Copyright (c) 2013 TNTTechnologies Inc.
// =============================================================================

#region

using System.Windows;
using System.Windows.Controls;

#endregion

namespace FVI.ControlBase{
    public class SimpleSplitter : UserControl{
        private Grid grid = new Grid();
        private DockPanel leftStack = new DockPanel();
        private DockPanel rightStack = new DockPanel();

        public SimpleSplitter(){
            this.Content = this.grid;
            this.grid.RowDefinitions.Add(new RowDefinition());
            this.grid.ColumnDefinitions.Add(new ColumnDefinition());
            this.grid.ColumnDefinitions.Add(new ColumnDefinition(){ Width = new GridLength(0, GridUnitType.Auto) });
            this.grid.ColumnDefinitions.Add(new ColumnDefinition());

            GridSplitter splitter = new GridSplitter();
            splitter.ShowsPreview = true;
            splitter.SetValue(Grid.RowProperty, 0);
            splitter.SetValue(Grid.ColumnProperty, 1);

            splitter.VerticalAlignment = VerticalAlignment.Stretch;
            splitter.HorizontalAlignment = HorizontalAlignment.Stretch;
            splitter.Width = 10;
            this.grid.Children.Add(splitter);
            this.leftStack.VerticalAlignment = VerticalAlignment.Stretch;
            this.leftStack.HorizontalAlignment = HorizontalAlignment.Stretch;
            this.rightStack.VerticalAlignment = VerticalAlignment.Stretch;
            this.rightStack.HorizontalAlignment = HorizontalAlignment.Stretch;
            this.leftStack.SetValue(Grid.ColumnProperty, 0);
            this.rightStack.SetValue(Grid.ColumnProperty, 2);
            this.grid.Children.Add(this.leftStack);
            this.grid.Children.Add(this.rightStack);
        }

        public double LeftWidth{
            get{
                return this.grid.ColumnDefinitions[0].Width.Value;
            }
            set{
                this.grid.ColumnDefinitions[0] = new ColumnDefinition(){
                    Width = new GridLength(value, GridUnitType.Auto)
                };
            }
        }

        public double RightWidth{
            get{
                return this.rightStack.Width;
            }
            set{
                this.rightStack.Width = value;
            }
        }

        public UIElementCollection Left{
            get{
                return this.leftStack.Children;
            }
        }

        public UIElementCollection Right{
            get{
                return this.rightStack.Children;
            }
        }
    }
}